﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace leastsquare
{
    public class getab
    {
        //求b
        public static double getb(double[] xs, double[] ys, double ax, double ay)
        {
            double b = 0;
            double up = 0;
            double down = 0;
            for (int i = 0; i < xs.Length; i++)
            {
                up += (xs[i] - ax) * (ys[i] - ay);
                down += (xs[i] - ax) * (xs[i] - ax);

            }
            b = up / down;
            return b;
        }
        //求a
        public static double geta(double average1, double average2, double b)
        {
            double a = average2 - average1 * b;
            return a;
        }
    }
}
